package com.doraro.coal.moudle.supplier.controller;


import com.doraro.coal.exception.R;
import com.doraro.coal.moudle.supplier.model.entity.Fultbsupplier;
import com.doraro.coal.moudle.supplier.service.impl.FultbsupplierServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 * 供应商基本信息 前端控制器
 * </p>
 *
 * @author doraro
 * @since 2019-10-10
 */
@Controller

public class FultbsupplierRestController {
    @Autowired
    private FultbsupplierServiceImpl fultbsupplierService;

    @GetMapping("/dispSupplier")
    public String goDispSupplier(Model model) {
        List<Fultbsupplier> results = fultbsupplierService.findAllSupplier();
        model.addAttribute("suppliers",results);
        return "supplier/dispSupplier";
    }
    @GetMapping("/supplierDetails")
    public String goSupplierDetail(@RequestParam String id,Model model) {
        Fultbsupplier supplier=fultbsupplierService.getById(id);
         model.addAttribute("supplier",supplier);
        return "supplier/supplierDetails";
    }

    @GetMapping("/auditSupplier")
    public String auditSupplier() {
        return "supplier/auditSupplier";
    }
    @GetMapping("/monthlyScore")
    public String monthlyScore() {
        return "supplier/monthlyScore";
    }

    @GetMapping("/annualScore")
    public String annualScore() {
        return "supplier/annualScore";
    }
    @GetMapping("/annualScoreDetails")
    public String annualScoreDetails() {
        return "supplier/annualScoreDetails";
    }
    @GetMapping("/updateScore")
    public String updateScore() {
        return "supplier/updateScore";
    }


    @PostMapping("/changeclevel.do")
    @ResponseBody
    public R<String> changeclevel(String level, String id){

        Fultbsupplier supplier=fultbsupplierService.getById(id);
        supplier.setCreditlevel(level);
        fultbsupplierService.updateById(supplier);
        return R.success("success");
    }

    @GetMapping("/squery.do")
    public String squery(@RequestParam String supplierName,Model model){
        List<Fultbsupplier> results = fultbsupplierService
                .lambdaQuery()
                .like(StringUtils.isNotBlank(supplierName),Fultbsupplier::getName,supplierName)
                .list();
        model.addAttribute("suppliers",results);
        return "supplier/dispSupplier";


    }



}

